<?php
namespace Components\Account\User\Info;

class Service {
  public function findFirst($parameters = []) {
    $model = Model::findFirst($parameters);
    if(!$model) {
      return ['code' => -1, 'message' => '数据不存在或已删除'];
    }

    return ['code' => 0, 'model'=>$model];
  }

  public function updateById($id, $data) {
    $res = $this -> findFirst('user_id = ' . $id);
    if($res['code'] != 0) {
      return $res;
    }

    if(!$res['model'] -> update($data)) {
      $messages = $res['model'] -> getMessages();
      return ['code' => -1, 'message' => $messages[0] -> getMessage()];
    }

    return ['code'=>0,'message'=>'更新成功','model'=>$res['model']];
  }

  public function count($parameters = []) {
    return Model::count($parameters);
  }
}
